package newcrunch.typography;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 * @author WL
 */
public class TypoDetailsModel <T> extends AbstractTableModel
{
    private ArrayList[] column;
    private String[] columnHeaders;
    
    public TypoDetailsModel(String[] names)
    {
        column = new ArrayList[names.length];
        columnHeaders = new String[names.length];
        
        for (int i = 0; i < names.length; i++)
        {
            columnHeaders[i] = names[i];
            column[i] = new ArrayList<T>();
        }
    }
    
    public void addRow(T... args)
    {
        for (int i = 0; i < args.length; i++)
            column[i].add(args[i]);
    }
    
    public void reset()
    {
        for (int i = 0; i < column.length; i++)
            column[i].clear();
    }
    
    @Override
    public int getRowCount() {
        return column.length == 0 ? 0 : column[0].size();
    }

    @Override
    public int getColumnCount() {
        return columnHeaders.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return columnHeaders[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return String.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return column[columnIndex].get(rowIndex);
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        column[columnIndex].add(rowIndex, aValue);
    }
}
